package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.*;

public class MenuBar implements ActionListener,ItemListener
{
	private JMenuItem[] menuItems;
	private JMenuBar menuBar;
	private JMenu menu;
	private Gui gui;

	public MenuBar(Gui g)
	{
		this.gui = g;
		this.menuBar = new JMenuBar();
		this.menu = new JMenu("Game");
		this.menuItems = new JMenuItem[2];

		//Add the menu item's
		this.menuItems[0] = new JMenuItem("New Game");
		this.menuItems[1] = new JMenuItem("Exit");

		//Set the action listeners
		this.menuItems[0].addActionListener(this);
		this.menuItems[1].addActionListener(this);

		//Add the menu items to the menu
		this.menu.add(menuItems[0]);
		this.menu.add(menuItems[1]);

		//Add the menu to the bar
		this.menuBar.add(menu);

		//Done, the bar is made visible in the 'Gui' class
	}

	public JMenuBar getMenuBar()
	{
		return this.menuBar;
	}
	
	public void actionPerformed(ActionEvent e)
	{
		//Retrieve the clicked menuitem
		JMenuItem clickedItem = (JMenuItem) e.getSource();
		
		//Pass on the selected ai
		if (clickedItem.getText().equals("New Game"))
		{
			this.gui.displayNewGameMenu();
			gui.repaint();
		}
		else if (clickedItem.getText().equals("Exit"))
		{
			System.exit(0);
		}

	}

	public void itemStateChanged(ItemEvent e) { }
	
}

